<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
    <title>登录</title>
    <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
</head>
<body>
<div class="form-group">
    <label class="col-sm-3 control-label"> <em style="color: red;font-style: normal;">*</em> 门店图片：</label>
    <div class="col-sm-8">
        <div class="mendian">+</div>
        <input type="file" id="fileUp" >
    </div>
</div>

<input type="submit" id="submit"  value="66666666666666666"/>
<script type="application/javascript">

    var tx_base64 = "" ; //图片路径

    $("#submit").on("click",function(){
        upload();
    });

    function upload(){
        /* 此处获取上传图片的base64码*/
        var a = $(".mendian").css("background");
        a = a.substring(a.indexOf("base64,") + 7, a.length - '") repeat scroll 50% 50% / cover padding-box border-box'.length);

        var storeData = new Object();
        storeData.imgMechanics = a;
        //还有其他实体此处忽略
        $.ajax({
            cache: true,
            type: "POST",
            url: "http://localhost:8080/pc/upload/uploadBase64File",
            data: JSON.stringify(storeData),//JSON序列化
            contentType: "application/json",//比较关键

            // 只做上传测试可以忽略返回操作部分
            error: function (request) {
                parent.layer.alert("Connection error");
            },
            success: function (data) {
                if (data.code == 0) {
                    parent.layer.msg("操作成功");
                    parent.reLoad();
                    var index = parent.layer.getFrameIndex(window.name); // 获取窗口索引
                    parent.layer.close(index);

                } else {
                    parent.layer.alert(data.msg)
                }
            }
        });
    }
    //门店图片上传图片选择及回显
    $(".mendian").click(function () {
        $("#fileUp").click()
    });
    $('#fileUp').on('change',function(e){
        var b=$("#fileUp").val();
        $("#fbgimg").val(new Date().getTime()+ "_" +b.substr(b.lastIndexOf("\\")+1));
        var file = e.target.files || e.dataTransfer.files;
        if (file) {
            var reader = new FileReader();
            reader.onload = function () {
                $('.mendian').html("");
                $('.mendian').css({"background":" url(" + this.result + ") center center","background-size":"cover"});
                tx_base64 = this.result;
            }
            reader.readAsDataURL(file[0]);
        }
    });
</script>
</body>
</html>